package com.yh;

import com.yh.cache.GoodsCache;
import com.yh.cache.ShoppingCache;
import com.yh.service.ShoppingService;
import com.yh.service.impl.ShoppingServiceImpl;

import java.math.BigDecimal;

public class Shopping {

    static ShoppingService shoppingService = new ShoppingServiceImpl();

    public static void shoppingByA(){
        //放商品进购物车
        ShoppingCache.shoppingCache.put(1L,10);
        ShoppingCache.shoppingCache.put(2L,10);

        //结算
        System.out.println("A购买总额为："+shoppingService.allPrice().toString()+"元");

        //清空购物车
        ShoppingCache.shoppingCache.clear();
    }

    public static void shoppingByB(){
        //放商品进购物车
        ShoppingCache.shoppingCache.put(1L,10);
        ShoppingCache.shoppingCache.put(2L,10);
        ShoppingCache.shoppingCache.put(3L,5);

        //结算
        System.out.println("B购买总额为："+shoppingService.allPrice().toString()+"元");
        ShoppingCache.shoppingCache.clear();

    }

    public static void shoppingByC(){
        //放商品进购物车
        ShoppingCache.shoppingCache.put(1L,10);
        ShoppingCache.shoppingCache.put(2L,10);
        ShoppingCache.shoppingCache.put(3L,5);

        //结算
        try {
            System.out.println("C购买总额为："+shoppingService.allPriceByAllowance("0.8").toString()+"元");
        } catch (Exception e) {
            System.out.println("折扣错误");
        }
        ShoppingCache.shoppingCache.clear();
    }

    public static void shoppingByD(){
        //放商品进购物车
        ShoppingCache.shoppingCache.put(1L,10);
        ShoppingCache.shoppingCache.put(2L,10);
        ShoppingCache.shoppingCache.put(3L,5);

        //结算
        System.out.println("D购买总额为："+shoppingService.allPriceByFullDecrement(new BigDecimal("100"),new BigDecimal("10"))+"元");

        ShoppingCache.shoppingCache.clear();
    }



    public static void main(String[] args) {

        shoppingByA();
        shoppingByB();
        shoppingByC();
        shoppingByD();

    }

}
